<?php /* УТФ-8:fix */

define( 'SPI_IAM_PERM_GUEST',               0 );
define( 'SPI_IAM_PERM_ADMIN',               1 );
define( 'SPI_IAM_PERM_USER',                2 );

SPIcfg::init();

class SPIcfg
{
    static public $project_name     = 'Інтернет магазин обладнання';
    static public $project_slogan   = 'Найкращий вибір товарів саме у нас!';
    static public $project_url      = 'http://...';

    static public $hostnames        = array();
    static public $langList         = array();
    static public $dir              = array();
    static public $store            = array();
    static public $media            = array();
    static public $tpl              = array();
    static public $util             = array();
    static public $is_dev           = false;
    static public $isShowScriptExt  = false;

    static public function init()
    {
        self::$is_dev = true;
        self::$isShowScriptExt = false;

        //-----------------------------------------------------------------------------

        iconv_set_encoding( 'internal_encoding',        'UTF-8' );
        error_reporting(E_ALL  & ~E_NOTICE);
        date_default_timezone_set('Europe/Kiev');

        //-----------------------------------------------------------------------------
        // Dirs & URLs config

        self::$hostnames['base']                        = 'http://...';

        if( self::$is_dev )
        {
            self::$hostnames['base']                    = 'http://shop.ua/';
        }

        self::$dir['root']                              = str_replace('\\\\','/',dirname(__FILE__)).'/';
        self::$dir['core']                              = self::$dir['root'] . 'spider.core/';

        self::$dir['cache']                             = self::$dir['root'] . 'cache/';
        self::$dir['languages']                         = self::$dir['root'] . 'languages/';
        self::$dir['log']                               = self::$dir['root'] . 'log/';
        self::$dir['store']                             = self::$dir['root'] . 'store/';
        self::$dir['store_public']                      = self::$dir['root'] . 'store/public/';
        self::$dir['styles']                            = self::$dir['root'] . 'styles/';
        self::$dir['utils']                             = self::$dir['root'] . 'spider.utils/';

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$dir['pubsite_root']                      = '/';

        if( self::$is_dev )
        {
            self::$dir['pubsite_root']                  = '/';
        }

        self::$dir['pubsite_styles']                    = self::$dir['pubsite_root'] . 'styles/';
        self::$dir['pubsite_store']                     = self::$dir['pubsite_root'] . 'store/';
        self::$dir['pubsite_store_public']              = self::$dir['pubsite_root'] . 'store/public/';

        //-----------------------------------------------------------------------------
        // Конфігурація медіа
        self::$media['basedir']                         = self::$dir['store'].'media/';
        self::$media['cache_basedir']                   = self::$dir['cache'].'media/';
        self::$media['preview_script']                  = 'media.php';
        self::$media['preview_width']                   = 180;
        self::$media['preview_height']                  = false;

        //-----------------------------------------------------------------------------
        // Store config

        self::$store['default_store_id']                = 'mysql';

		
        if( self::$is_dev )
        {
			self::$store['main']['type']                    = 'PGSQL';
			self::$store['main']['hostname']                = 'localhost';
			self::$store['main']['username']                = 'postgres';
			self::$store['main']['password']                = 'postgres';
			self::$store['main']['database']                = 'postgres';
			self::$store['main']['encoding']                = 'utf8';
			self::$store['main']['search_path']             = 'public';
			
			self::$store['mysql']['type']                    = 'MYSQL';
			self::$store['mysql']['hostname']                = 'localhost';
			self::$store['mysql']['username']                = 'root';
			self::$store['mysql']['password']                = '';
			self::$store['mysql']['database']                = 'shop_protect';
			self::$store['mysql']['encoding']                = 'utf8';
		}
		else
		{
			self::$store['main']['type']                    = 'PGSQL';
			self::$store['main']['hostname']                = 'localhost';
			self::$store['main']['username']                = 'umbk';
			self::$store['main']['password']                = 'i7RReRya';
			self::$store['main']['database']                = 'box44203_umbk';
			self::$store['main']['encoding']                = 'utf8';
			self::$store['main']['search_path']             = 'public';
			
			self::$store['mysql']['type']                    = 'MYSQL';
			self::$store['mysql']['hostname']                = 'localhost';
			self::$store['mysql']['username']                = 'root';
			self::$store['mysql']['password']                = '';
			self::$store['mysql']['database']                = 'shop_protect';
			self::$store['mysql']['encoding']                = 'utf8';
		}

        self::$store['table:consts']                    = 'consts';
        self::$store['table:content']                   = 'content';
        self::$store['table:media']                     = 'media';
        self::$store['table:profiles']                  = 'profiles';
        self::$store['table:singlepages']               = 'singlepages';
		self::$store['table:catalogs']                  = 'catalogs';
		self::$store['table:brands']                    = 'brands';
		self::$store['table:filters']                   = 'filters';
		self::$store['table:params']                    = 'params';
		self::$store['table:content_params']            = 'params_ref_content';

        self::$store['sequence:global']                 = 'global_id_seq';

        //-----------------------------------------------------------------------------
        // Templates config

        self::$tpl['manage']['type']                    = 'SMARTY';
        self::$tpl['manage']['compile_check']           = self::$is_dev ? true : false;
        self::$tpl['manage']['template_dir']            = self::$dir['styles'].'manage/templates/';
        self::$tpl['manage']['config_dir']              = self::$dir['styles'].'manage/templates/';
        self::$tpl['manage']['cache_dir']               = false;
        self::$tpl['manage']['compile_dir']             = self::$dir['cache'].'smarty/templates_c_manage/';
        self::$tpl['manage']['config_load']             = array();
        self::$tpl['manage']['load_filter']             = array('output:trimwhitespace');

        self::$tpl['front']['type']                     = 'SMARTY';
        self::$tpl['front']['compile_check']            = self::$is_dev ? true : false;
        self::$tpl['front']['template_dir']             = self::$dir['styles'].'front/templates/';
        self::$tpl['front']['config_dir']               = self::$dir['styles'].'front/templates/';
        self::$tpl['front']['cache_dir']                = false;
        self::$tpl['front']['compile_dir']              = self::$dir['cache'].'smarty/templates_c_front/';
        self::$tpl['front']['config_load']              = array();
        self::$tpl['front']['load_filter']              = array('output:trimwhitespace');

        self::$tpl['enotifier']['type']                 = 'SMARTY';
        self::$tpl['enotifier']['compile_check']        = self::$is_dev ? true : false;
        self::$tpl['enotifier']['template_dir']         = self::$dir['styles'].'enotifier/templates/';
        self::$tpl['enotifier']['config_dir']           = self::$dir['styles'].'enotifier/templates/';
        self::$tpl['enotifier']['cache_dir']            = false;
        self::$tpl['enotifier']['compile_dir']          = self::$dir['cache'].'smarty/templates_c_enotifier/';
        self::$tpl['enotifier']['config_load']          = array();
        self::$tpl['enotifier']['load_filter']          = array();

        //-----------------------------------------------------------------------------
        // Utilities config

        self::$util['smarty']['base_script']            = self::$dir['utils'].'Smarty/libs/Smarty.class.php';

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$util['json']['base_script']              = self::$dir['utils'].'json/Services_JSON.php';

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$util['excel']['reader']['cache_basedir'] = self::$dir['cache'].'excel_buffer/';

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$util['spaw2']['base_script']             = self::$dir['utils'].'spaw2/spaw.inc.php';
        self::$util['spaw2']['store']                   = self::$dir['store_public'];
        self::$util['spaw2']['spaw_root']               = '/spider.utils/spaw2/';
        self::$util['spaw2']['pubsite_store']           = self::$dir['pubsite_store_public'];
        self::$util['spaw2']['default_css']             = self::$dir['pubsite_styles'] . 'manage/css/spaw2.default.css?build=300120101';

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$util['minify']['basedir']                = self::$dir['utils'].'minify/';
        self::$util['minify']['cache_basedir']          = self::$dir['cache'].'minify/';
        self::$util['minify']['build']                  = '14122011' . ( self::$is_dev ? '.dev'.time() : '' );

        //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        self::$util['captcha']['source']                = 'captcha.php';
        self::$util['captcha']['font_source']           = self::$dir['utils'].'captcha/font.ttf';

        //-----------------------------------------------------------------------------

        ini_set('session.gc_maxlifetime', 2*60*60 );        # Session time -> 2 hours

        return true;
    }

    public function as_array()
    {
        return array(
            'project_name'      => self::$project_name,
            'project_slogan'    => self::$project_slogan,
            'project_url'       => self::$project_url,
            'dir'               => self::$dir,
            'store'             => self::$store,
            'media'             => self::$media,
            'tpl'               => self::$tpl,
            'util'              => self::$util,
            'is_dev'            => self::$is_dev,
        );
    }
}


function vd( $data )
{
	echo"<pre style='border:1px solid grey;'>".var_export($data, true)."</pre>";
}